// 以成员函数作为定时器回调函数。
#include <muduo/net/EventLoop.h>
#include <boost/bind.hpp>
#include <boost/noncopyable.hpp>
#include <iostream>

using namespace muduo::net;
using namespace std;

class Printer : boost::noncopyable {
public:
	Printer(EventLoop *loop)
		: loop_(loop), count_(0) {
		loop_->runAfter(1, boost::bind(&Printer::Print, this));
	}

	~Printer() {
		cout << "final count is " << count_ << endl;
	}

private:
	void Print() {
		if (count_ < 5) {
			cout << "****** " << count_ << endl;
			++count_;
			loop_->runAfter(1, boost::bind(&Printer::Print, this));
		} else {
			loop_->quit();
		}
	}

	EventLoop *loop_;
	int count_;
};

int 
main() {
	EventLoop loop;
	Printer printer(&loop);
	loop.loop();
	return 0;
}